package com.telit.firecommand.controller;


import com.telit.common.entity.*;
import com.telit.common.util.BaiduUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;


@RestController
@RequestMapping("/baidu")
@Api(tags = "百度地图", description = "百度地图")
public class BaiduMapController {

    @GetMapping(value = "/drving/{origin}/{destination}/{coord_type}", produces = "application/json;charset=UTF-8")
    @ApiOperation("驾车路线规划")
    public DataReturn driving(@PathVariable("origin") String origin, @PathVariable("destination") String destination,
                              @PathVariable("coord_type") String coordType) {
        BaiduMapInfo<Result> driving = BaiduUtils.driving(origin, destination, coordType);
        return DataReturn.ok(driving);
    }

    @GetMapping(value = "/riding/{origin}/{destination}/{coord_type}", produces = "application/json;charset=UTF-8")
    @ApiOperation("骑行路线规划")
    public DataReturn riding(@PathVariable("origin") String origin, @PathVariable("destination") String destination,
                             @PathVariable("coord_type") String coordType) {
        BaiduMapInfo<Result> riding = BaiduUtils.riding(origin, destination, coordType);
        return DataReturn.ok(riding);
    }

    @GetMapping(value = "/walking/{origin}/{destination}/{coord_type}", produces = "application/json;charset=UTF-8")
    @ApiOperation("步行路线规划")
    public DataReturn walking(@PathVariable("origin") String origin, @PathVariable("destination") String destination,
                              @PathVariable("coord_type") String coordType) {
        BaiduMapInfo<Result> walking = BaiduUtils.walking(origin, destination, coordType);
        return DataReturn.ok(walking);
    }

    @GetMapping(value = "/promptAddress", produces = "application/json;charset=UTF-8")
    @ApiOperation("地址查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "地址", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "province", value = "省份", paramType = "query", dataType = "string", required = false),
            @ApiImplicitParam(name = "region", value = "区域", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "county", value = "区县", paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "cityLimit", value = "默认false。取值为true，仅返回region中指定城市检索结果", defaultValue = "true", paramType = "query", dataType = "boolean"),
            @ApiImplicitParam(name = "coordType", value = "坐标系", paramType = "query", dataType = "string")})
    public DataReturn promptAddress(String query, @RequestParam(required = false) String province, String region,
                                    String county, String coordType,
                                    @RequestParam(required = false, value = "cityLimit", defaultValue = "false") boolean cityLimit)
            throws UnsupportedEncodingException {
        BaiduMapInfo baiduMapInfo = BaiduUtils.promptAddress(query, province, region, county, coordType, cityLimit);
        return DataReturn.ok(baiduMapInfo);
    }

    @GetMapping(value = "/searchAddress", produces = "application/json;charset=UTF-8")
    @ApiOperation("poi检索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "地址", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "region", value = "区域", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "coordType", value = "坐标系", paramType = "query", dataType = "string")})
    public DataReturn searchAddress(String query, String region, String coordType) throws UnsupportedEncodingException {
        POIMapInfo poiMapInfo = BaiduUtils.searchAddress(query, region, coordType);
        return DataReturn.ok(poiMapInfo);
    }

    @GetMapping(value = "/getDetailAddress", produces = "application/json;charset=UTF-8")
    @ApiOperation("地点详细信息")
    @ApiImplicitParam(name = "uid", value = "地址编号", paramType = "query", dataType = "string", required = true)
    public DataReturn getDetailAddress(String uid) throws UnsupportedEncodingException {
        BaiduMapInfo<DetailAddressResult> baiduMapInfo = BaiduUtils.getDetailAddress(uid);
        return DataReturn.ok(baiduMapInfo);
    }

}
